package v1beta1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
	imageReasonWaitForGuest      = "waitForGuestReady"
	imageReasonWaitForNatGateway = "waitForNatGateway"
	imageReasonCreateFailed      = "CreateFailed"
)

// ImageSpec defines the desired state of image
type ImageSpec struct {
	OwnerId          string           `json:"owner_id,omitempty"`
	ResourceAffinity ResourceAffinity `json:"resourceAffinity,omitempty"`
	CloudResourceId  string           `json:"cloudresource_id,omitempty"`
	ProviderRef      ProviderRef      `json:"providerRef,omitempty"`
	GuestRef         GuestRef         `json:"guestRef,omitempty"`
	Description      string           `json:"description,omitempty"`
	OrderInfo        OrderInfo        `json:"orderInfo,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=img
// +kubebuilder:subresource:status

// Image is the Schema for the image API
type Image struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   ImageSpec   `json:"spec,omitempty"`
	Status ImageStatus `json:"status,omitempty"`
}

type ImageStatus struct {
	Phase     ImagePhaseType `json:"phase,omitempty"`
	ImageInfo ImageInfo      `json:"info,omitempty"`
	ImageId   string         `json:"imageId,omitempty"`
	// +optional
	Conditions []Condition `json:"conditions,omitempty"`
}
type ImageInfo struct {
	OsType    string `json:"osType,omitempty"`
	OsVersion string `json:"osVersion,omitempty"`
	CpuArch   string `json:"cpuArch,omitempty"`
	Size      int64  `json:"size,omitempty"`
}

type ImagePhaseType string

const (
	ImageCreatingPhase ImagePhaseType = "Creating"
	ImageReadyPhase    ImagePhaseType = "Ready"
	ImageFailedPhase   ImagePhaseType = "Failed"
	ImagePendingPhase  ImagePhaseType = "Pending"
	ImageCreateFailed  ImagePhaseType = "CreateFailed"
)

type GuestRef struct {
	Name       string `json:"name"`
	Namespace  string `json:"namespace"`
	InstanceId string `json:"instanceId"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ImageList contains a list of image item
type ImageList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Image `json:"items"`
}
